import React from 'react';
import Relay from "react-relay";
import LoginMutation from "./login/mutation/LoginMutation.js"
import EventManager from './util/EventManager.js'
import Main from './ms/main/Main.js'
import Login from './login/Login.js'
import { hashHistory } from 'react-router'

export default class Hello extends React.Component {
  
  constructor(){
    super();
    this.state={
      islogin:true
    }
  }
  
  componentWillMount(){
    EventManager.on('islogin',(param)=>{
      this.setState({
        islogin:param
      });
    });
    let uid = sessionStorage.getItem('uid');
    // let token = sessionStorage.getItem('token');
    //(token==null || token=='null'|| token=='') ||
    if((uid==null || uid=='null'|| uid=='')){
      hashHistory.push('/');
      EventManager.emitter('islogin',false);
    }else{
      EventManager.emitter('islogin',true);
    }


    // Relay.Store.commitUpdate(
    //     new LoginMutation({
    //         username: "admin",
    //         password: "123453",
    //
    //     }),
    //     {
    //       onFailure: () => {
    //         alert('请求失败');
    //       },
    //       onSuccess: (response) => {
    //         if(response.login.loginResponse.errorCode==0){
    //           EventManager.emitter('islogin',true);
    //         }else{
    //           EventManager.emitter('islogin',false);
    //         }
    //
    //       }
    //     }
    // )
  }

  
  render() {
    return (
        <div>
          {
              this.state.islogin
                  ?
                  <Main />
                  :
                  <Login />
          }

        </div>
    );
  }
}